/**
 * Licensed under the Apache License Version 2.0.
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package net.interknit.knitter.cg.cfg;

import java.util.ArrayList;
import java.util.List;

import org.jdom.Element;

/**
 *
 */
public class TargetEl extends TypeEl
{
	private PropertiesEl properties = new PropertiesEl();
	private ParentsEl parents = new ParentsEl();
	private List<MethodEl> methods = new ArrayList<MethodEl>();

	TargetEl()
	{
		;
	}

	/**
	 * @return the properties
	 */
	public PropertiesEl getProperties()
	{
		return properties;
	}

	/**
	 * @return the parents
	 */
	public ParentsEl getParents()
	{
		return parents;
	}

	/**
	 * @return the methods
	 */
	public List<MethodEl> getMethods()
	{
		return methods;
	}

	public TargetEl(Element el)
	{
		super(el);

		properties = new PropertiesEl(el.getChild("properties"));

		Element parentsEl = el.getChild("parents");
		if(parentsEl != null)
			parents = new ParentsEl(parentsEl);

		Element methodsEl = el.getChild("methods");
		if(methodsEl != null)
		{
			methods = new ArrayList<MethodEl>();
			for(Element methodEl : (List<Element>) methodsEl.getChildren("method"))
				methods.add(new MethodEl(methodEl));
		}
	}

	@Override
	public String toString()
	{
		String val = "<target classname=\"" + getClassName() + "\" restname=\"" + getRestName() + "\">" + "\n";

		val = val + "<comments>" + getComments() + "</comments>";

		if(properties != null) val = val + properties.toString() + "\n";

		if(parents != null) val = val + parents.toString() + "\n";

		val = val + "<methods>" + "\n";
		for(MethodEl method : methods)
			val = val + method.toString() + "\n";
		val = val + "</methods>" + "\n";

		val = val + "</target>";

		return val;
	}
}
